
package com.bi2.events.mobile;

import com.bi2.events.mobile.entities.Usuario;
import com.bi2.events.mobile.utils.WebService;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends Activity {

    private Button search_events_btn;
    private Button search_friends_btn;
    private Button my_profile_btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        this.my_profile_btn = (Button) this.findViewById(R.id.my_profile_btn);
        this.my_profile_btn.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                carregarPerfil();
            }
        });
        

        this.search_events_btn = (Button) this.findViewById(R.id.search_events_btn);
        this.search_events_btn.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                procurarEventos();
            }
        });

        this.search_friends_btn = (Button) this.findViewById(R.id.search_friends_btn);
        this.search_friends_btn.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                procurarAmigos();
            }
        });

        // Instantiate the Web Service Class with he URL of the web service not
        // that you must pass

        try {
        WebService webService = new WebService("http://192.168.254.100:8080/Events/resources/usuarios");

        // Pass the parameters if needed , if not then pass dummy one as follows
        Map<String, String> params = new HashMap<String, String>();
        params.put("", "1");

        // Get JSON response from server the "" are where the method name would
        // normally go if needed example
        // webService.webGet("getMoreAllerts", params);
        String response = webService.webGet("", params);

            // Parse Response into our object
            Type collectionType = new TypeToken<List<Usuario>>() {
            }.getType();
            List<Usuario> alrt = new Gson().fromJson(response, collectionType);
            Log.d("Lista: ", alrt.get(1).toString());

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    protected void procurarAmigos() {
        Intent procurarAmigos = new Intent(this, SearchFriendsActivity.class);
        startActivity(procurarAmigos);
    }

    protected void procurarEventos() {
        Intent searchEvents = new Intent(this, SearchEventsActivity.class);
        startActivity(searchEvents);
    }

    protected void carregarPerfil() {
        Intent profile = new Intent(this, InternalActivity.class);
        startActivity(profile);
    }

    protected void carregarMuralUsuario() {
        Intent muralUsuario = new Intent(this, InternalActivity.class);
        startActivity(muralUsuario);
    }

    @Override
    protected void onStart() {
        super.onStart();
    }
}
